package org.lboot.idmo.validator;

import cn.hutool.core.lang.Validator;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

public class IsSexValidator implements ConstraintValidator<IsSex, Object> {
    @Override
    public void initialize(IsSex constraintAnnotation) {
        ConstraintValidator.super.initialize(constraintAnnotation);
    }

    @Override
    public boolean isValid(Object o, ConstraintValidatorContext constraintValidatorContext) {
        if (Validator.isEmpty(o)){
            return true;
        }
        String sex = o.toString();
        return sex.equals("男") || sex.equals("女");
    }
}
